import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import React, { useEffect, useState } from 'react';
import './Header.css';
dayjs.locale('zh-cn'); // 设置当前语言环境为中文

const Time: React.FC = () => {
  const [date, setDate] = useState('');
  const [week, setWeek] = useState('');

  useEffect(() => {
    const timer = setInterval(() => {
      setDate(dayjs().format('YYYY/MM/DD HH:mm:ss'));
      setWeek(dayjs().format('dddd'));
    }, 1000);

    return () => {
      clearInterval(timer);
    };
  }, []);

  return (
    <div className="header_right">
      <div className='header_right_date'>
        <span>{week}</span>
        <span className='marginl-10'>{date.split(' ')[0]}</span>
      </div>
      <div className='header_right_time'>{date.split(' ')[1]}</div>
    </div>
  );
};

export default Time;
